<template>
  <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <div class="Logout">
      <Logout>退出</Logout>

   <div class="image">
       <el-image :src="src2"></el-image>
       <!-- <el-image :src="src1"></el-image> -->
    </div>
     



    </div>
<!--    <el-button type="danger" @click="Logout">退出登录</el-button>-->
    <h1>添加家谱信息</h1>
    
   
   
  

     <el-form-item label="家谱ID" prop="zid">
      <el-input style="width: 800px" v-model="ruleForm.zid" placeholder="请输入家谱ID" prefix-icon="el-icon-s-check" maxlength="10" show-word-limit clearable></el-input>
    </el-form-item>
   
   <el-form-item label="用户ID" prop="zpartner">
      <el-input style="width: 800px" v-model="ruleForm.zpartner" placeholder="请输入用户ID" prefix-icon="el-icon-s-management" maxlength="50" show-word-limit clearable></el-input>
    </el-form-item>


  <el-form-item label="家谱名称" prop="zname">
      <el-input style="width: 800px" v-model="ruleForm.zname" placeholder="请输入家谱名称" prefix-icon="el-icon-user-solid" maxlength="50" show-word-limit clearable></el-input>
    </el-form-item>
   
   
<el-form-item label="内容描述" prop="zbirth">
      <el-input style="width: 800px" v-model="ruleForm.zbirth" placeholder="请输入内容描述" prefix-icon="el-icon-s-management" maxlength="50" show-word-limit clearable></el-input>
    </el-form-item>
   
   
<!-- 
     <el-form-item label="家训" prop="zdie">
      <el-input style="width: 800px" v-model="ruleForm.zdie" placeholder="请输入家训" prefix-icon="el-icon-s-management" maxlength="50" show-word-limit clearable></el-input>
    </el-form-item> -->


 <!-- <el-form-item label="族长" prop="zmarry">
      <el-input style="width: 800px" v-model="ruleForm.zmarry" placeholder="请输入族长" prefix-icon="el-icon-s-management" maxlength="50" show-word-limit clearable></el-input>
    </el-form-item> -->

 
    


 



<!-- <el-form-item label="家谱" prop="zchild">
      <el-input style="width: 800px" v-model="ruleForm.zchild" placeholder="请输入子女信息" prefix-icon="el-icon-s-management" maxlength="50" show-word-limit clearable></el-input>
    </el-form-item> -->

<!-- 
<el-form-item label="恩荣录" prop="zlife">
      <el-input style="width: 800px" v-model="ruleForm.zlife" placeholder="请输入生平事迹" prefix-icon="el-icon-s-management" maxlength="50" show-word-limit clearable></el-input>
    </el-form-item> -->

<!-- <el-form-item label="联系方式" prop="zaddress">
      <el-input style="width: 800px" v-model="ruleForm.zaddress" placeholder="请输入族长联系方式" prefix-icon="el-icon-s-management" maxlength="50" show-word-limit clearable></el-input>
    </el-form-item> -->


<el-form-item label="创建时间" prop="zhonor">
      <el-input style="width: 800px" v-model="ruleForm.zhonor" placeholder="请输入创建时间" prefix-icon="el-icon-s-management" maxlength="50" show-word-limit clearable></el-input>
    </el-form-item>


    <el-form-item>
      <el-button type="success" @click="submitForm('ruleForm')" icon="el-icon-check">提交</el-button>
      <el-button type="danger" @click="resetForm('ruleForm')" icon="el-icon-refresh">重置</el-button>
    </el-form-item>
  </el-form>
  
 





</template>

<script>
import Logout from "./Logout";
export default {
  name: "AddZupu",
  components: {Logout},
  data () {
    return {

       src2:"https://pic3.zhimg.com/v2-6a7f42399d208412f642615b665787f6_b.jpg",
      ruleForm: {
        zid: '',
        zname: '',
    //    zlevel: '',
    //    ztype: '',
        zaddress: '',
        zdie:'',
        zmarry:'',
        zpartner:'',
        zlife:'',
        zbirth:'',
        zchild:'',
        zhonor:'',
      },
      rules: {
        zid:
          {required: true, message: '请输入家谱ID', trigger: 'blur'},

        zname:
          {required: true, message: '请输入家谱名称', trigger: 'blur'},

    //      zlevel:
    //      {required: true, message: '请输入等级', trigger: 'change'},

    //    ztype:
    //     {required: true, message: '请输入特长', trigger: 'blur'},

        // zaddress:
        //   {required: true, message: '请输入家庭地址', trigger: 'blur'},

          // zdie:
          // {required: true, message: '请输入死亡时间', trigger: 'blur'},

          // zmarry:
          // {required: true, message: '请输入结婚日期', trigger: 'blur'},

           zpartner:
          {required: true, message: '请输入配偶信息', trigger: 'blur'},

          // zlife:
          // {required: true, message: '请输入生平事迹', trigger: 'blur'},

          
          zbirth:
          {required: true, message: '请输入内容描述', trigger: 'blur'},

          // zchild:
          // {required: true, message: '请输入子女信息', trigger: 'blur'},

          zhonor:
          {required: true, message: '请输入创建时间', trigger: 'blur'},

      },
    }
  },
  methods : {
    submitForm(formName) {
      const _this=this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log(_this.ruleForm)
          //这个地方进行axios提交后台信息
          const params = {
            zno:_this.ruleForm.zid,
            zname:_this.ruleForm.zname,
       //     zlevel:_this.ruleForm.zlevel,
       //     zcharacter:_this.ruleForm.ztype,
            zaddress: _this.ruleForm.zaddress,
            tdie:_this.ruleForm.zdie,
            zmarry:_this.ruleForm.zmarry,
            zpartner:_this.ruleForm.zpartner,
            zlife:_this.ruleForm.zlife,
            zbirth:_this.ruleForm.zbirth,
            zchild:_this.ruleForm.zchild,
            zhonor:_this.ruleForm.zhonor

          }
          console.log("zno:", params.zno, " zname:", params.zname, " zlevel:", params.zlever, " zc:", params.zcharacter)
   
          
          this.$axios.post(`/InsertZupu`,params).then((res) => {   // 请求后端  给后端传参数  在执行then（res）之前，先向后端请求，前端一直等待后端返回的状态码
            console.log(res);   
            if (res.data.msg=="插入家谱成功") { //如果返回信息，则插入成功
              alert("插入家谱成功")
            } else {
              alert("插入家谱失败")
            }
          });
        
        }
      });
    },


   
   
   
   
   
   //       this.$axios.post(`/InsertZupu`,params).then((res) => {   // 请求后端  给后端传参数  在执行then（res）之前，先向后端请求，前端一直等待后端返回的状态码
    //         console.log(res);   
    //         if (res.data.msg=="插入家族成员成功") { //如果返回信息，则插入成功
    //           alert("插入家族成员成功")
    //         } else {
    //           alert(res.data.msg)
    //         }
    //       });
    //       //alert('提交成功!');
    //     }
    //   });
    // },

    // this.$axios.post(`/InsertZupu`,params).then((res) => {   // 请求后端  给后端传参数  在执行then（res）之前，先向后端请求，前端一直等待后端返回的状态码
    //         console.log(res);   
    //         if (res.data.msg=="插入家谱成功") { //如果返回信息，则插入成功
    //           alert("插入家谱成功")
    //         } else {
    //           alert("插入家谱失败")
    //         }
    //       });
         
    //     }
    //   });
    // },




    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    Logout() {
      var _this = this;
      _this.$confirm('确认退出吗？', '提示', {}).then(() => {
        window.location.href = '/'
      }).catch(() => {})
    },
  }
}
</script>

<style scoped>

</style>
